package com.project.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.project.bean.CoachBean;
import com.project.bean.CoachDTO;
import com.project.bean.FolloweBean;
import com.project.bean.LessonBean;
import com.project.bean.PageBean;
import com.project.bean.PostBean;
import com.project.dao.CoachMapper;
import com.project.dao.LessonMapper;
import com.project.service.ICoachService;



@Service
public class CoachServiceImpl implements ICoachService{
	@Autowired
	private CoachMapper coachMapper;
	@Autowired
	private LessonMapper lessonMapper;

	@Override
	public int completeInformation(CoachBean coachBean) {
		// TODO Auto-generated method stub
		return coachMapper.updateByUid(coachBean);
	}

	@Override
	public CoachBean findCoachById(Integer cUId) {
		// TODO Auto-generated method stub
		return coachMapper.findByUid(cUId);
	}

	@Override
	public List<CoachBean> findAllCoachs() {
		// TODO Auto-generated method stub
		return coachMapper.findAll();
	}

	@Override
	public int addCoach(Integer cUId) {
		// TODO Auto-generated method stub
		return coachMapper.insertCuid(cUId);
	}

	@Override
	public PageBean findAllCoachsByPage(Integer page,Integer size) {
		PageBean pageBean=new PageBean();
		Map<String,Integer> map=new HashMap<String,Integer>();
		map.put("page", (page-1)*size);
		map.put("size", size);
		List<CoachBean> list=coachMapper.findAllByPage(map);
		int num=coachMapper.findAll().size();
		int totalpage=(num%size==0)?(num/size):(num/size+1);
		pageBean.setPage(page);
		pageBean.setSize(size);
		pageBean.setTotalNumber(num);
		pageBean.setTotalPage(totalpage);
		pageBean.setList(list);
		return pageBean;
	}

	@Override
	public PageBean findConditionCoachsByPage(CoachDTO coachDTO,Integer page,Integer size) {
		PageBean pageBean=new PageBean();		
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("page", (page-1)*size);
		map.put("size", size);
		map.put("CoachDTO", coachDTO); 
		List<String> list=coachMapper.findConditionByPage(map);
		int num = coachMapper.findcondition(map);
		int totalpage=(num%size==0)?(num/size):(num/size+1);
		pageBean.setPage(page);
		pageBean.setSize(size);
		pageBean.setTotalNumber(num);
		pageBean.setTotalPage(totalpage);
		pageBean.setList(list);
		return pageBean;	
	
	}
	
	@Override
	public int addCoachCUId(int cuid) {
		
		return coachMapper.addCoachCUId(cuid);
	}

	@Override
	public int updateCoachtMessage(String sRealname, int cAge, int cGender, int cSchool, int id) {
	
		return coachMapper.updateCoachtMessage(sRealname, cAge, cGender, cSchool, id);
	}

	@Override
	public int updateQuality(int quality,int cUId) {
		CoachBean coach = new CoachBean();
		coach.setcUId(cUId);
		coach.setcQuality(quality);
		coachMapper.updateByCUIdSelective(coach);
		return cUId;
		
	}

}
